<template>
  <div>
    <div class="mg-r-20">
      <MainTextList :textList="textList"></MainTextList>
    </div>
    <el-card class="box-card">
      <div class="news_header">
        <MainSearchForm :formList="formList" :formValue="formValue" @formReset="formChange" @formSearch="formChange"></MainSearchForm>
        <el-button size="mini" class="add-btn" @click="addRelation">新增</el-button>
        <!-- <el-button size="mini">导出</el-button> -->
      </div>
      <div class="mg-t-16" style="min-height: 600px">
        <MainTable
          ref="orderTable"
          :loading="listLoading"
          :columns="columns"
          :tableData="tableData"
          :tree-props="{children: 'supplier_list', hasChildren: 'hasChildren'}"
        >
          <template #selection>
            <el-table-column type="expand" class-name="main_hei">
              <template slot-scope="props">
                <el-table
                  :data="props.row.supplier_list"
                  class="child-table"
                  fit
                  :highlight-current-row="false"
                >
                  <el-table-column label width="40" align="right" />
                  <el-table-column label="合同编号" prop="contract_no" />
                  <el-table-column label="供应商名称" prop="name" />
                  <el-table-column label="联系人" prop="contacts" width="200" />
                  <el-table-column label="手机号" prop="mobile" />
                </el-table>
              </template>
            </el-table-column>
          </template>
          <template v-slot:status="{ row }">
            <span :style="{ color: row.status == 1 ? '#03A98E' : '#999999' }">{{ row.status === 1 ? '绑定' : '解除' }}</span>
          </template>
          <template v-slot:supplier_name="{ row }">
            <span>{{ row.supplier_name }} ({{ row.supplier_total }})</span>
          </template>
          <el-table-column label="操作" width="200">
            <template slot-scope="scope">
              <MainLink title="编辑" color="#42BEAA" @linkClick="lookList(scope.row, 2)"></MainLink>
              <MainLink title="查看" color="#444444" @linkClick="lookList(scope.row, 1)"></MainLink>
            </template>
          </el-table-column>
        </MainTable>
      </div>

      <div class="pagination-right">
        <MainPagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40]"
          :page-size="pageSize"
          layout=" ->,total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </MainPagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import MainTextList from '@/components/MainTextList/textList.vue'
import { getRelationTotal, getRelationList } from "@/api/relation";
import { getBannerList, deleteBannerList } from "@/api/news/banner";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import MainTable from '@/components/MainTable/table.vue'
import { indexData } from '../MockData'
const { columns, tableData, formList, formValue, textList } = indexData
export default {
  name: "news",
  components: {
    MainTable, MainTextList
  },
  data() {
    return {
      handleScrool: "",
      formList,
      formValue,
      sendTime: [],
      tableData,
      currentPage: 1,
      pageSize: 20,
      total: 0,
      // 勾选的数据
      multipleSelection: [],
      // 新闻日期
      pickerOptions: [],
      listLoading: false,
      dialogData:{
        title:"",
        status:false,
        mydata:{}
      },
      columns,
      textList
    };
  },
  activated() {
    this.getData();
  },
  mounted() {
    this.getTabsNum()
    this.getData()
  },
  methods: {
    load(tree, treeNode, resolve) {
    },
    //  新增关系
    addRelation() {
      this.$router.push({
        path: "/relation/detail",
        query: {
          pageControls: 0
        }
      });
    },
     //  表单搜索
    formChange() {
      this.currentPage = 1
      this.pageSize = 20
      this.getData()
    },
    //  获取总数
    getTabsNum() {
      getRelationTotal().then(res => {
        if(res.errcode == 0) {
          this.textList.forEach(el => {
            el.num = res.data[el.key]
          })
        }
      }).catch(err => {
        console.log(err);
      })
    },
    //  获取列表数据
    getData() {
      this.listLoading = true;
      let data = {
        page: this.currentPage,
        page_size: this.pageSize,
        ...this.formValue
      };
      getRelationList(data).then(
        (res) => {
          this.listLoading = false;
          this.tableData = res.data.list.map(el => {
            return {
              ...el,
              children: [],
              hasChildren: true
            }
          });
          this.total = res.data.total;
        },
        (err) => {
          console.log(err);
        }
      );
    },
    //  查看
    lookList(row, pageControls) {
      this.$router.push({
        path: "/relation/detail",
        query: {
          id: row.id,
          pageControls
        }
      });
    },
    close(){
      this.dialogData.status=false;
      location.reload()
    },
    // 状态
    changeSwitch(e, row) {
      console.log("1", e, row);
    },

    // 勾选的数据
    handleSelectionChange(val) {
      console.log("val", val);
      this.multipleSelection = val;
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getData();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val;
      this.getData();
    },
  },
  created() {
  },
};
</script>
<style lang="scss" scoped>
@import '../index.scss';
</style>
